home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import gtk
- import gtk.gdk as gtk
- import gobject
- import os
- import invest
- from gettext import gettext as _
- from invest import *
- import sys
- from os.path import join
- import urllib
- from threading import Thread
- import time
- AUTOREFRESH_TIMEOUT = 1200000
-
- class _IdleObject(gobject.GObject):
- '''
- \tOverride gobject.GObject to always emit signals in the main thread
- \tby emmitting on an idle handler
- \t'''
-
- def __init__(self):
- gobject.GObject.__init__(self)
-
-
- def emit(self, *args):
- gobject.idle_add(gobject.GObject.emit, self, *args)
-
-
-
- class ImageRetriever(Thread, _IdleObject):
- '''
- \tThread which uses gobject signals to return information
- \tto the GUI.
- \t'''
- __gsignals__ = {
- 'completed': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []) }
-
- def __init__(self, image_url):
- Thread.__init__(self)
- _IdleObject.__init__(self)
- self.image_url = image_url
- self.retrieved = False
-
-
- def run(self):
- self.image = gtk.Image()
-
- try:
- sock = urllib.urlopen(self.image_url, proxies = invest.PROXY)
- except:
- if invest.DEBUGGING:
- print 'Error while opening %s' % self.image_url
-
-
- loader = gtk.gdk.PixbufLoader()
- loader.connect(('closed',), (lambda loader: self.image.set_from_pixbuf(loader.get_pixbuf())))
- loader.write(sock.read())
- sock.close()
- loader.close()
- self.retrieved = True
- self.emit('completed')
-
-
-
- class FinancialChart:
-
- def __init__(self, ui):
- self.ui = ui
- win = ui.get_object('window')
- win.set_title(_('Financial Chart'))
-
- try:
- pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(join(invest.ART_DATA_DIR, 'invest_neutral.svg'), 96, 96)
- self.ui.get_object('plot').set_from_pixbuf(pixbuf)
- except Exception:
- msg = None
-
- for widget in [
- 't',
- 'q']:
- ui.get_object(widget).set_active(0)
-
- symbolentry = ui.get_object('s')
-
- refresh_chart_callback = lambda w: self.on_refresh_chart()
- for widgets, signal in [
- (('pm5', 'pm10', 'pm20', 'pm50', 'pm100', 'pm200', 'pe5', 'pe10', 'pe20', 'pe50', 'pe100', 'pe200', 'pb', 'pp', 'ps', 'pv', 'ar', 'af', 'ap', 'aw', 'am', 'ass', 'afs', 'av', 'avm'), 'toggled'),
- (('t', 'q'), 'changed'),
- (('s',), 'activate')]:
- for widget in widgets:
- ui.get_object(widget).connect(signal, refresh_chart_callback)
-
-
- ui.get_object('progress').hide()
- self.autorefresh_id = 0
- ui.get_object('autorefresh').connect('toggled', self.on_autorefresh_toggled)
-
-
- def on_refresh_chart(self, from_timer = False):
- tickers = self.ui.get_object('s').get_text()
- if tickers.strip() == '':
- return True
- tickers = _[1]
- win = self.ui.get_object('window')
- title = _('Financial Chart - %s')
- titletail = ''
- for ticker in tickers:
- titletail += '%s / ' % ticker
-
- title = title % titletail
- win.set_title(title[:-3])
- opt = ''
- for ticker in tickers[1:]:
- opt += '&c=%s' % ticker
-
- p = ''
- for name, param in [
- ('pm5', 5),
- ('pm10', 10),
- ('pm20', 20),
- ('pm50', 50),
- ('pm100', 100),
- ('pm200', 200),
- ('pe5', 5),
- ('pe10', 10),
- ('pe20', 20),
- ('pe50', 50),
- ('pe100', 100),
- ('pe200', 200),
- ('pb', ''),
- ('pp', ''),
- ('ps', ''),
- ('pv', '')]:
- if self.ui.get_object(name).get_active():
- p += '%s%s,' % (name[1], param)
- continue
- []
-
- a = ''
- for name, param in [
- ('ar', 14),
- ('af', 14),
- ('ap', 12),
- ('aw', 14),
- ('am', '26-12-9'),
- ('ass', ''),
- ('afs', ''),
- ('av', ''),
- ('avm', '')]:
- if self.ui.get_object(name).get_active():
- a += '%s%s,' % (name[1:], param)
- continue
- []
-
- chart_base_url = 'http://ichart.europe.yahoo.com/z?s=%(s)s&t=%(t)s&q=%(q)s&l=%(l)s&z=%(z)s&p=%(p)s&a=%(a)s%(opt)s'
- url = chart_base_url % {
- 's': tickers[0],
- 't': self.ui.get_object('t').get_active_text(),
- 'q': self.ui.get_object('q').get_active_text(),
- 'l': 'off',
- 'z': 'l',
- 'p': p,
- 'a': a,
- 'opt': opt }
- progress = self.ui.get_object('progress')
- progress.set_text(_('Opening Chart'))
- progress.show()
- image_retriever = ImageRetriever(url)
- image_retriever.connect('completed', self.on_retriever_completed)
- image_retriever.start()
- self.on_autorefresh_toggled(self.ui.get_object('autorefresh'))
- return True
-
-
- def on_retriever_completed(self, retriever):
- self.ui.get_object('plot').set_from_pixbuf(retriever.image.get_pixbuf())
- progress = self.ui.get_object('progress')
- if retriever.retrieved == True:
- progress.set_text(_('Chart downloaded'))
- else:
- progress.set_text(_('Chart could not be downloaded'))
-
-
- def on_autorefresh_toggled(self, autorefresh):
- if self.autorefresh_id != 0:
- gobject.source_remove(self.autorefresh_id)
- self.autorefresh_id = 0
-
- if autorefresh.get_active():
- self.autorefresh_id = gobject.timeout_add(AUTOREFRESH_TIMEOUT, self.on_refresh_chart, True)
-
-
-
-
- def show_chart(tickers):
- ui = gtk.Builder()
- ui.add_from_file(os.path.join(invest.BUILDER_DATA_DIR, 'financialchart.ui'))
- chart = FinancialChart(ui)
- ui.get_object('s').set_text(' '.join(tickers))
- chart.on_refresh_chart()
- return ui.get_object('window')
-
-